package com.quartz.example;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.time.LocalDateTime;

public class QuartzTwo implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        Object one = context.getTrigger().getJobDataMap().get("one");
        Object two = context.getTrigger().getJobDataMap().get("two");
        Object three = context.getJobDetail().getJobDataMap().get("three");
        Object four = context.getJobDetail().getJobDataMap().get("four");

        Object girl = null;
        try {
             girl = context.getScheduler().getContext().get("girl");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        System.out.println(one);
        System.out.println(two);
        System.out.println(three);
        System.out.println(four);
        System.out.println(girl);
        System.out.println(LocalDateTime.now());
    }

    public static void main(String[] args) throws  Exception{
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
  //      scheduler.getContext().put("girl","gril-杨贵妃");

        Trigger trigger = TriggerBuilder.newTrigger()
              //  .withIdentity("A队","A队-A计划")
               // .usingJobData("one","one-一拳超人")
               // .usingJobData("two","two-二龙升天")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever())
                .build();

//        trigger.getJobDataMap().put("one","one");
//        trigger.getJobDataMap().put("two","two");

        JobDetail job = JobBuilder.newJob(QuartzTwo.class)
              //  .usingJobData("three","three-三羊开泰")
               // .usingJobData("four","four-四季发财")
               // .withIdentity("B队","B队-b计划")
                .build();

//        job.getJobDataMap().put("three","three");
//        job.getJobDataMap().put("four","four");

        scheduler.scheduleJob(job,trigger);
        scheduler.start();

    }
}
